package com.sjc.springbootdemo.mapper;

import com.sjc.springbootdemo.domain.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Classname UserMapper
 * @Description 用户管理模块的Mapper组件
 * @Date 2020/4/23 14:58
 * @Created by SangJiacun
 */
@Mapper
public interface UserMapper {
    @Select("SELECT * FROM user")
    List<User> listUsers();

    @Select("SELECT * FROM user WHERE user_id = #{userId}")
    User getUserById(@Param("userId") Long userId);

    @Insert("INSERT INTO user(name, age) VALUES(#{name}, #{age})")
    @Options(useGeneratedKeys = true, keyProperty = "userId")
    void saveUser(User user);

    @Update("UPDATE user SET name=#{name}, age=#{age} WHERE user_id=#{userId}")
    int updateUser(User user);

    @Delete("DELETE FROM user WHERE user_id=#{userId}")
    int removeUser(@Param("userId") Long userId);
}
